package com.fr.report.core.barcode.pdf417;

import com.fr.report.core.barcode.Module;
import com.fr.report.core.barcode.output.AbstractOutput;

public class PDF417Module extends Module
{
  private static final int DATACOLS = 12;
  private final String data;
  private int[] out;
  private int outlen;
  private int outrows;
  private int col = 0;
  private int xp;
  private int yp;
  private int startX;
  private int wsize = 0;
  private int barWidth;

  public PDF417Module(String paramString)
  {
    super(new int[0]);
    this.data = paramString;
  }

  int getBarcodeWidth()
  {
    return (this.wsize - this.startX);
  }

  int getBarcodeHeight()
  {
    return this.yp;
  }

  protected double draw(AbstractOutput paramAbstractOutput, double paramDouble1, double paramDouble2)
  {
    this.xp = (int)paramDouble1;
    this.startX = (int)paramDouble1;
    this.yp = (int)paramDouble2;
    this.barWidth = (int)paramAbstractOutput.getBarWidth();
    createCodewords(this.data.toCharArray(), this.data.length());
    createBits(this.out, this.outlen, this.outrows);
    encode(this.out, this.outrows, paramAbstractOutput);
    return getBarcodeWidth();
  }

  private void generateEC(int[] paramArrayOfInt, int paramInt1, int paramInt2)
  {
    int i = 0;
    int j = 0;
    int k = 27;
    int l = 917;
    paramArrayOfInt[paramInt1] = 0;
    paramArrayOfInt[(paramInt1 + 1)] = 0;
    if (paramInt2 != 2)
      return;
    for (int i1 = 0; i1 < paramInt1; ++i1)
    {
      int i2 = (j + paramArrayOfInt[i1]) % 929;
      if (i2 != 0)
        i2 = 929 - i2;
      j = (i + l * i2) % 929;
      i = (0 + k * i2) % 929;
    }
    if (i != 0)
      i = 929 - i;
    if (j != 0)
      j = 929 - j;
    paramArrayOfInt[paramInt1] = j;
    paramArrayOfInt[(paramInt1 + 1)] = i;
  }

  private void outbit(int paramInt, AbstractOutput paramAbstractOutput)
  {
    paramAbstractOutput.drawBar(this.xp, this.yp, 1, 1, paramInt == 1);
    this.xp += this.barWidth;
    if (this.col++ == this.wsize - 1)
    {
      this.col = 0;
      this.yp += 1;
      this.xp = this.startX;
    }
  }

  private void createCodewords(char[] paramArrayOfChar, int paramInt)
  {
    int i = 2;
    this.outlen = (2 + paramInt / 6 * 5 + paramInt % 6 + i);
    this.outrows = (this.outlen / 12);
    if (this.outlen % 12 != 0)
      this.outrows += 1;
    if (this.outrows < 3)
      this.outrows = 3;
    if (this.outrows > 90)
      return;
    this.outlen = (this.outrows * 12);
    if (this.outlen > 928)
      return;
    this.out = new int[this.outlen];
    this.out[0] = (2 + paramInt / 6 * 5 + paramInt % 6);
    if (paramInt % 6 != 0)
      this.out[1] = 901;
    else
      this.out[1] = 924;
    int j = 0;
    for (int k = 2; j + 5 < paramInt; k += 5)
    {
      long l = 0L;
      for (int i1 = 0; i1 < 6; ++i1)
      {
        l <<= 8;
        l += paramArrayOfChar[(j++)];
      }
      for (i1 = 0; i1 < 5; ++i1)
      {
        this.out[(k + 4 - i1)] = new Long(l % 900L).intValue();
        l /= 900L;
      }
    }
    while (j < paramInt)
      this.out[(k++)] = paramArrayOfChar[(j++)];
    while (k < this.outlen - i)
      this.out[(k++)] = 900;
    generateEC(this.out, k, i);
  }

  private void createBits(int[] paramArrayOfInt, int paramInt1, int paramInt2)
  {
    if ((paramInt2 < 3) || (paramInt2 > 90) || (paramInt1 != 12 * paramInt2))
      return;
    int l = paramInt2 * 16;
    int[] arrayOfInt = new int[l];
    int k = 0;
    int j = 0;
    for (int i = 0; i < paramInt2; ++i)
    {
      int i1 = 11;
      int i2 = i % 3;
      int i3 = i / 3;
      int i4 = paramInt2 / 3;
      int i5 = 0 + paramInt2 % 3;
      arrayOfInt[(k++)] = 130472;
      switch (i2)
      {
      case 0:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i4)];
        break;
      case 1:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i5)];
        break;
      case 2:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i1)];
      }
      for (int i6 = 0; i6 < 12; ++i6)
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][paramArrayOfInt[(j++)]];
      switch (i2)
      {
      case 0:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i1)];
        break;
      case 1:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i4)];
        break;
      case 2:
        arrayOfInt[(k++)] = PDF417Data.PDF417_BITS[i2][(30 * i3 + i5)];
      }
      arrayOfInt[(k++)] = 130324;
    }
    this.out = arrayOfInt;
    this.outlen = l;
  }

  private void encode(int[] paramArrayOfInt, int paramInt, AbstractOutput paramAbstractOutput)
  {
    int i2;
    int j = 7;
    int k = 2;
    this.wsize = ((272 + this.barWidth + 4) * k);
    for (int l = 0; l < 2 * k; ++l)
      for (i2 = 0; i2 < 277 * k; ++i2)
        outbit(0, paramAbstractOutput);
    for (l = 0; l < paramInt; ++l)
      for (i2 = 0; i2 < j; ++i2)
      {
        for (int i3 = 0; i3 < 2 * k; ++i3)
          outbit(0, paramAbstractOutput);
        for (i3 = 0; i3 < 16; ++i3)
        {
          int i = paramArrayOfInt[(16 * l + i3)];
          for (int i4 = 16; i4 >= 0; --i4)
            for (int i5 = 0; i5 < k; ++i5)
              if ((i & 1 << i4) != 0)
                outbit(1, paramAbstractOutput);
              else
                outbit(0, paramAbstractOutput);
        }
        for (i3 = 0; i3 < k; ++i3)
          outbit(1, paramAbstractOutput);
        for (i3 = 0; i3 < 2 * k; ++i3)
          outbit(0, paramAbstractOutput);
      }
    for (int i1 = 0; i1 < 2 * k; ++i1)
      for (i2 = 0; i2 < 277 * k; ++i2)
        outbit(0, paramAbstractOutput);
  }
}